package com.stockz.scanner.screen;

import java.util.List;

import com.stockz.core.model.Bar;
import com.stockz.core.util.BarUtil.BarValueType;
import com.stockz.indicator.movingAverage.simple.SimpleMovingAverageIndicator;
import com.stockz.indicator.stochastics.StochasticsIndicator;
import com.stockz.scanner.screen.configuration.SellingClimaxScreenConfiguration;

public class SellingClimaxScreen implements Screen<SellingClimaxScreenConfiguration> {

	private final SimpleMovingAverageIndicator simpleMovingAverageIndicator = new SimpleMovingAverageIndicator();
	private final StochasticsIndicator stochasticsIndicator = new StochasticsIndicator();
	private final SellingClimaxScreenConfiguration configuration = new SellingClimaxScreenConfiguration();
	
	@Override
	public int getMandatorySpan() {
		return configuration.getSpan()+1;
	}
	
	@Override
	public SellingClimaxScreenConfiguration getConfiguration() {
		return configuration;
	}
	
	@Override
	public boolean isMatch(List<Bar> barList) {
		
		if(barList == null || barList.size() < configuration.getSpan()){
			return false;
		}
		
		stochasticsIndicator.setBarValueType(BarValueType.AVGPRICE);
		stochasticsIndicator.getIndicatorConfiguration().setSpan(configuration.getSpan());
		double stochastics = stochasticsIndicator.getValue(barList);
		
		simpleMovingAverageIndicator.getIndicatorConfiguration().setSpan(configuration.getSpan());
		simpleMovingAverageIndicator.setBarValueType(BarValueType.VOLUME);
		double vsma = simpleMovingAverageIndicator.getValue(barList);
		
		Bar bar = barList.get(0);
		
		if(stochastics < configuration.getStochasticsUpperLimit()
				&& bar.getVolume() > vsma*configuration.getVolumeMultiple()){
		return true;	
		}
		
		return false;
	}
	
}
